package com.six.backend.shiro.Utils;

import com.six.backend.token.JwtToken;
import com.six.backend.utils.EncryptUtil;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.springframework.stereotype.Component;

/**
 * @Author: skyler
 * @Date: 2021/11/6 20:20
 */
@Component
public class myCredentialsMatcher extends SimpleCredentialsMatcher {

    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        System.out.println("执行了密码验证器");
        JwtToken jwtToken = (JwtToken) token;
        if (jwtToken.getPassword() == null) {
            return true;
        }
        String inPassword = new String(jwtToken.getPassword());
        String dbPassword = (String) info.getCredentials();
        return this.equals(inPassword,EncryptUtil.decrypt(dbPassword));
    }
}
